/*
 * svgimage.cpp SVG渲染器
 */
#include "svgimage.h"
#include <qdebug.h>
#include <QTimer>
#include <QRegion>
#include <QPointF>

SvgImage::SvgImage(QQuickItem *parent) : QQuickPaintedItem(parent)
{
    m_pSvgRenderer = new QSvgRenderer(this);
}

void SvgImage::declareQML()
{
    qmlRegisterType<SvgImage>("SvgImage", 1, 0, "SvgImage");
}

void SvgImage::writeSource(QString sourcePath) {
    if(sourcePath.length() != 0)
    {
        m_source = sourcePath;
        m_source.replace("qrc", "");
        m_pSvgRenderer->load(m_source);
        emit sourceChanged();
        update();
    }
}

void SvgImage::paint(QPainter *painter)
{
    QRectF rect = QRectF(QPointF(x(),y()), QSizeF(width(), height()));
    //qDebug() << "width" << width();
    //qDebug() << "height" << height();
    m_pSvgRenderer->render(painter, rect);
}
